package t327.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import t327.mapper.ExpendAndIncomeMapper;
import t327.pojo.Expend;
import t327.service.iter.IExpendAndIncomeService;

import java.util.HashMap;
import java.util.List;
@Service
@Transactional
public class ExpendAndIncomeServiceImpl implements IExpendAndIncomeService {
    @Autowired
    private ExpendAndIncomeMapper expendAndIncomeMapper;

    @Override
    public HashMap<String,String> addExpendAndIncome(Expend expend) {
        HashMap<String,String> map = new HashMap<>();
        int i = expendAndIncomeMapper.addExpendAndIncome(expend);
        if(i>0){
            map.put("code","200");
            map.put("msg","添加成功");
        }else {
            map.put("code","203");
            map.put("msg","添加失败");
        }

        return map;
    }

    @Override
    public List<Expend> getAllExpendAndIncome() {
        return expendAndIncomeMapper.getAllExpendAndIncome();
    }
    @Override
    public List<Expend> getExpendAndIncomeByCond(Long expendStatus) {
        if (expendStatus != 0){
            return expendAndIncomeMapper.getExpendAndIncomeByCond(expendStatus);
        }else {
            return expendAndIncomeMapper.getAllExpendAndIncome();
        }
    }
}
